package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.Carinfo;
import com.stylefeng.guns.modular.system.service.ICarinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * 车辆信息表控制器
 *
 * @author fengshuonan
 * @Date 2018-08-23 17:44:18
 */
@Controller
@RequestMapping(value = {"/gunsApi/auth/carinfo"})
public class CarinfoController extends BaseController {

    private String PREFIX = "/system/carinfo/";

    @Autowired
    private ICarinfoService carinfoService;

    /**
     * 跳转到车辆信息表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "carinfo.html";
    }

    /**
     * 跳转到添加车辆信息表
     */
    @RequestMapping("/carinfo_add")
    public String carinfoAdd() {
        return PREFIX + "carinfo_add.html";
    }

    /**
     * 跳转到修改车辆信息表
     */
    @RequestMapping("/carinfo_update/{carinfoId}")
    public String carinfoUpdate(@PathVariable Integer carinfoId, Model model) {
        Carinfo carinfo = carinfoService.selectById(carinfoId);
        model.addAttribute("item",carinfo);
        LogObjectHolder.me().set(carinfo);
        return PREFIX + "carinfo_edit.html";
    }

    /**
     * 获取车辆信息表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return carinfoService.selectList(null);
    }

    /**
     * 新增车辆信息表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Carinfo carinfo) {
        carinfoService.insert(carinfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除车辆信息表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer carinfoId) {
        carinfoService.deleteById(carinfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改车辆信息表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Carinfo carinfo) {
        carinfoService.updateById(carinfo);
        return SUCCESS_TIP;
    }

    /**
     * 车辆信息表详情
     */
    @RequestMapping(value = "/detail/{carinfoId}")
    @ResponseBody
    public Object detail(@PathVariable("carinfoId") Integer carinfoId) {
        return carinfoService.selectById(carinfoId);
    }
}
